home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / DOS32VBE.ZIP / DOS32VBE.DOC < prev    next >
Encoding:
Text File  |  1996-12-16  |  15.4 KB  |  488 lines

  1.  
  2.         Small doc on using SVGA with DOS32.
  3.  
  4. 1. Check if the videomode we want is supported on the computer.
  5.    The problem here is that we need some low memory, where we can let the VBE
  6.    put some info about the mode.  This is solved, however, by using the 8k
  7.    buffer that DOS32 uses for file I/O.
  8.    (We'll make a near ptr to the videomemory when we're at function 0ee02h
  9.     anyway.)
  10.  
  11. --->8----- API.DOC ----------
  12.                    GET DOS32 ADDRESS INFORMATION            V3.01+
  13.  
  14.  IN:    AX = EE02h
  15.  
  16.  OUT:   EBX = 32bit linear address of the program segment
  17.         EDX = Total size in bytes of the programs .EXE file after
  18.                linking.
  19.         ESI = Offset address of PSP ( Program Segment Prefix )
  20.         EDI = Offset address of Program Environment
  21.         ECX = Offset address of the programs .EXE file name and
  22.                path (in ASCIZ format, i.e. terminates with a zero)
  23.          AX = Real mode segment value of the 8Kb buffer that is
  24.                used by the file read/write services.
  25. ---8<----- API.DOC ----------
  26.  
  27.    The values we need here are AX and EBX, we need to make a near pointer out
  28.    of that realmode segment value.
  29.  
  30.    lowmemptr       dd      ?
  31.    lowmemseg       dw      ?
  32.    linearadr       dd      ?
  33.    videomem        dd      ?
  34.  
  35.    mov     eax,0ee02h
  36.    int     31h
  37.    mov     lowmemseg,ax
  38.    mov     linearadr,ebx
  39.    push    ax      ;\
  40.    xor     eax,eax ; > Clears the high bits of eax
  41.    pop     ax      ;/
  42.    shl     eax,4   ; Makes eax the absolute address of the RM segment
  43.    sub     eax,ebx ; Makes eax a near pointer to the RM segment
  44.    mov     lowmemptr,eax
  45.    mov     eax,0a0000h
  46.    sub     eax,ebx
  47.    mov     videomem,eax
  48.  
  49.    Now when we have our segment, and accompanying near pointer, we can make a
  50.    real mode callback to the VBE.
  51.  
  52. --->8----- API.DOC ----------
  53. ...expects a pointer to a real
  54. mode call structure whish is used to passing all registers to and
  55. from the real mode switch. The format of the structure is defined
  56. as:                      Offset     Register
  57.                           00h         EDI
  58.                           04h         ESI
  59.                           08h         EBP
  60.                           0Ch  Reserved by system
  61.                           10h         EBX
  62.                           14h         EDX
  63.                           18h         ECX
  64.                           1Ch         EAX
  65.                           20h         Flags
  66.                           22h         ES
  67.                           24h         DS
  68.                           26h         FS
  69.                           28h         GS
  70.                           2Ah         IP
  71.                           2Ch         CS
  72.                           2Eh         SP
  73.                           30h         SS
  74.  
  75.                   Simulate a Real Mode interrupt            V3.00+
  76.  
  77. IN:
  78.         AX = 0300h
  79.         BL = Interrupt number
  80.         BH = Flags
  81.              Bit 0  = 1 resets the interrupt controller and A20
  82.              line. Other flags reserved and must be 0
  83.        CX =  Number of  words to  copy from  protected mode to
  84.              real mode stack
  85.        ES:EDI = Selector:Offset of real mode call structure
  86.  
  87. OUT:
  88.       If function was successful:
  89.       Carry flag is clear.
  90.       ES:(E)DI =  Selector:Offset of  modified real mode call
  91.                   structure
  92.  
  93.       If function was not successful:
  94.        Carry flag is set.
  95. ---8<----- API.DOC ----------
  96.  
  97.    So, we need a structure defined as described in API.DOC:
  98.  
  99. --->8----- GFX.ASM ----------
  100. _    label
  101. _edi    label    dword
  102. _di    label    word
  103. _dih    db    ?
  104. _dil    db    ?
  105. _edih    db    ?
  106. _edil    db    ?
  107. _esi    label    dword
  108. _si    label    word
  109. _sih    db    ?
  110. _sil    db    ?
  111. _esih    db    ?
  112. _esil    db    ?
  113. _ebp    label    dword
  114. _bp    label    word
  115. _bph    db    ?
  116. _bpl    db    ?
  117. _ebph    db    ?
  118. _ebpl    db    ?
  119. _reserv    dd    ?
  120. _ebx    label    dword
  121. _bx    label    word
  122. _bh    db    ?
  123. _bl    db    ?
  124. _ebh    db    ?
  125. _ebl    db    ?
  126. _edx    label    dword
  127. _dx    label    word
  128. _dh    db    ?
  129. _dl    db    ?
  130. _edh    db    ?
  131. _edl    db    ?
  132. _ecx    label    dword
  133. _cx    label    word
  134. _ch    db    ?
  135. _cl    db    ?
  136. _ech    db    ?
  137. _ecl    db    ?
  138. _eax    label    dword
  139. _ax    label    word
  140. _ah    db    ?
  141. _al    db    ?
  142. _eah    db    ?
  143. _eal    db    ?
  144. _flags    dw    ?
  145. _es    dw    ?
  146. _ds    dw    ?
  147. _fs    dw    ?
  148. _gs    dw    ?
  149. _ip    dw    ?
  150. _cs    dw    ?
  151. _sp    dw    ?
  152. _ss    dw    0
  153. ---8<----- GFX.ASM ----------
  154.  
  155. --->8----- INTERRUP.LST ----------
  156. --------V-104F00-----------------------------
  157. INT 10 - VESA SuperVGA BIOS (VBE) - GET SuperVGA INFORMATION
  158.         AX = 4F00h
  159.         ES:DI -> buffer for SuperVGA information (see #0063)
  160. Return: AL = 4Fh if function supported
  161.         AH = status
  162.             00h successful
  163.                 ES:DI buffer filled
  164.             01h failed
  165.             ---VBE v2.0---
  166.             02h function not supported by current hardware configuration
  167.             03h function invalid in current video mode
  168. Desc:   determine whether VESA BIOS extensions are present and the capabilities
  169.           supported by the display adapter
  170. SeeAlso: AX=4E00h,AX=4F01h,AX=7F00h,AX=A00Ch
  171. Index:  installation check;VESA SuperVGA
  172.  
  173. Format of SuperVGA information:
  174. Offset  Size    Description     (Table 0063)
  175.  00h  4 BYTEs   (ret) signature ("VESA")
  176.                 (call) VESA 2.0 request signature ("VBE2"), required to receive
  177.                   version 2.0 info
  178.  04h    WORD    VESA version number (one-digit minor version)
  179.  06h    DWORD   pointer to OEM name
  180.                 "761295520" for ATI
  181.  0Ah    DWORD   capabilities flags (see #0064)
  182.  0Eh    DWORD   pointer to list of supported VESA and OEM video modes
  183.                 (list of words terminated with FFFFh)
  184.  12h    WORD    total amount of video memory in 64K blocks
  185. ---VBE v1.x ---
  186.  14h 236 BYTEs  reserved
  187. ---VBE v2.0 ---
  188.  14h    WORD    OEM software version
  189.  16h    DWORD   pointer to vendor name
  190.  1Ah    DWORD   pointer to product name
  191.  1Eh    DWORD   pointer to product revision string
  192.  22h 222 BYTEs  reserved
  193. 100h 256 BYTEs  OEM scratchpad
  194. Notes:  the list of supported video modes is stored in the reserved portion of
  195.           the SuperVGA information record by some implementations, and it may
  196.           thus be necessary to either copy the mode list or use a different
  197.           buffer for all subsequent VESA calls
  198.         the 1.1 VESA document specifies 242 reserved bytes at the end, so the
  199.           buffer should be 262 bytes to ensure that it is not overrun; for
  200.           v2.0, the buffer should be 512 bytes
  201.         the S3 specific video modes will most likely follow the FFFFh
  202.           terminator at the end of the standard modes.  A search must then
  203.           be made to find them, FFFFh will also terminate this second list
  204.  
  205. Bitfields for VESA capabilities:
  206. Bit(s)  Description     (Table 0064)
  207.  0      DAC can be switched into 8-bit mode
  208.  1      non-VGA controller
  209.  2      programmed DAC with blank bit
  210.  3-31   reserved
  211. ---8<----- INTERRUP.LST ----------
  212.  
  213.    Now, we need to set up the values to do the callback:
  214.  
  215.    mov     ax,lowmemseg
  216.    mov     _es,ax
  217.    mov     _di,0
  218.    mov     _ax,4f00h
  219.    mov     eax,300h
  220.    mov     ebx,10h
  221.    xor     ecx,ecx
  222.    lea     edi,_           ;our RM callback structure
  223.    int     31h
  224.  
  225.    If all went well, (ah=00h, al=4fh), we should now have a realmode seg:ofs ptr
  226.    to a word list of supported video modes.  Make it a near ptr and scan it to
  227.    see if what we want is available:
  228.  
  229.    cmp     _ax,4fh
  230.    jne     vbe_error
  231.    xor     eax,eax
  232.    xor     ebx,ebx
  233.    mov     ax,word ptr lowmemptr[0eh]
  234.    mov     bx,word ptr lowmemptr[10h]
  235.    shl     ebx,4
  236.    add     eax,ebx
  237.    sub     eax,linearadr
  238.    mov     esi,eax
  239.    mov     bx,101h         ;desired video mode
  240. loop1:
  241.    lodsw
  242.    cmp     ax,-1
  243.    je      mode_not_supported
  244.    cmp     ax,bx
  245.    jne     loop1
  246.  
  247.    We've got our video mode! :)
  248.  
  249. 2. We need the window granularity of this mode to do proper bankswitching.
  250.    This means interfacing the VBE, and using the RM buffer again.
  251.  
  252. --->8----- INTERRUP.LST ----------
  253. --------V-104F01-----------------------------
  254. INT 10 - VESA SuperVGA BIOS - GET SuperVGA MODE INFORMATION
  255.     AX = 4F01h
  256.     CX = SuperVGA video mode
  257.     ES:DI -> 256-byte buffer for mode information (see #0065)
  258. Return: AL = 4Fh if function supported
  259.     AH = status
  260.         00h successful
  261.         ES:DI buffer filled
  262.         01h failed
  263. Desc:    determine the attributes of the specified video mode
  264. SeeAlso: AX=4F00h,AX=4F02h
  265.  
  266. Format of VESA SuperVGA mode information:
  267. Offset    Size    Description    (Table 0065)
  268.  00h    WORD    mode attributes (see #0066)
  269.  02h    BYTE    window attributes, window A (see #0067)
  270.  03h    BYTE    window attributes, window B (see #0067)
  271.  04h    WORD    window granularity in KB
  272.  06h    WORD    window size in KB
  273.  08h    WORD    start segment of window A
  274.  0Ah    WORD    start segment of window B
  275.  0Ch    DWORD    -> FAR window positioning function (equivalent to AX=4F05h)
  276.  10h    WORD    bytes per scan line
  277. ---remainder is optional for VESA modes in v1.0/1.1, needed for OEM modes---
  278.  12h    WORD    width in pixels (graphics) or characters (text)
  279.  14h    WORD    height in pixels (graphics) or characters (text)
  280.  16h    BYTE    width of character cell in pixels
  281.  17h    BYTE    height of character cell in pixels
  282.  18h    BYTE    number of memory planes
  283.  19h    BYTE    number of bits per pixel
  284.  1Ah    BYTE    number of banks
  285.  1Bh    BYTE    memory model type (see #0068)
  286.  1Ch    BYTE    size of bank in KB
  287.  1Dh    BYTE    number of image pages
  288.  1Eh    BYTE    reserved (0)
  289. ---VBE v1.2+---
  290.  1Fh    BYTE    red mask size
  291.  20h    BYTE    red field position
  292.  21h    BYTE    green mask size
  293.  22h    BYTE    green field size
  294.  23h    BYTE    blue mask size
  295.  24h    BYTE    blue field size
  296.  25h    BYTE    reserved mask size
  297.  26h    BYTE    reserved mask position
  298.  27h    BYTE    direct color mode info
  299.         bit 0: color ramp is programmable
  300.         bit 1: bytes in reserved field may be used by application
  301. ---VBE v2.0 ---
  302.  28h    DWORD    physical address of linear video buffer
  303.  2Ch    DWORD    pointer to start of offscreen memory
  304.  30h    WORD    KB of offscreen memory
  305.  32h 206 BYTEs    reserved (0)
  306.  
  307. Bitfields for VESA SuperVGA mode attributes:
  308. Bit(s)    Description    (Table 0066)
  309.  0    mode supported
  310.  1    optional information available
  311.  2    BIOS output supported
  312.  3    set if color, clear if monochrome
  313.  4    set if graphics mode, clear if text mode
  314. ---VBE v2.0 ---
  315.  5    mode is not VGA-compatible
  316.  6    bank-switched mode not supported
  317.  7    linear framebuffer mode supported
  318.  
  319. Bitfields for VESA SuperVGA window attributes:
  320. Bit(s)    Description    (Table 0067)
  321.  0    exists
  322.  1    readable
  323.  2    writable
  324.  3-7    reserved
  325.  
  326. (Table 0068)
  327. Values for VESA SuperVGA memory model type:
  328.  00h    text
  329.  01h    CGA graphics
  330.  02h    HGC graphics
  331.  03h    16-color (EGA) graphics
  332.  04h    packed pixel graphics
  333.  05h    "sequ 256" (non-chain 4) graphics
  334.  06h    direct color (HiColor, 24-bit color)
  335.  07h    YUV (luminance-chrominance, also called YIQ)
  336.  08h-0Fh reserved for VESA
  337.  10h-FFh OEM memory models
  338. ---8<----- INTERRUP.LST ----------
  339.  
  340.    mov     ax,lowmemseg
  341.    mov     _es,ax
  342.    mov     _di,0
  343.    mov     _ax,4f01h
  344.    mov     _cx,101h        ;video mode
  345.    mov     eax,300h
  346.    mov     ebx,10h
  347.    xor     ecx,ecx
  348.    lea     edi,_           ;our RM callback structure
  349.    int     31h
  350.  
  351.    If all is OK, we will have the wgran parameter at offset 4 in the RM
  352.    segment.  However, it is specified in KB, so we need to shl with 10 to get
  353.    byte size.
  354.  
  355.    wgran   dd      ?
  356.  
  357.    cmp     _ax,4fh
  358.    jne     vbe_error
  359.    xor     ebx,ebx
  360.    mov     bx,word ptr lowmemptr[4]
  361.    shl     ebx,10
  362.    mov     wgran,ebx
  363.  
  364.    We've got granularity. :)
  365.  
  366. 3. Allocate memory for our virtual screen and switch to the SVGA mode.
  367.    This is really simple to do.
  368.  
  369. --->8----- API.DOC ----------
  370.                       ALLOCATE A MEMORY BLOCK               V3.00+
  371.  
  372.         The entire application code,data and stack is initially
  373. contained in one large memory block. This service here is used for
  374. allocating extra memory blocks for the application.
  375.  
  376.  IN:  AX = EE42h
  377.       EDX = Size of the memory block requested to allocate in
  378.           bytes.
  379.  
  380. OUT:  EAX = The actual allocated size of the memory block in bytes
  381.       EDX = Near pointer to the base address of the block relative
  382.             to the main program segment.
  383.  
  384.      If the returned size was less than the requested size then
  385.      the Carry flag is set otherwise the carry flag is cleared.
  386.  
  387.  Notes:
  388.   o  The value expected in EDX will be rounded off to the next
  389.      4KB boundary.  Example, allocating 51001h bytes will actually
  390.      allocate 52000h bytes.
  391.   o  Never call this function in a interrupt handler or after
  392.      using the terminated and stay resident function ( AX=EE30h ).
  393.   o  If EAX is returned with zero then no memory was allocated and
  394.      contents of EDX are undefined.
  395.   o  The function will fail if the requested size is zero.
  396.   o  No more than 64 allocations can be made. If the application
  397.      requires a faster more versatile memory management then
  398.      please use Peter Anderson's memory sub-functions from PAL
  399.      library. See example files on how to use. This function here
  400.      is should used a minimum number of times.
  401.   o  When not running under a DPMI server ( i.e  Raw,XMS or VCPI )
  402.      then extended memory is allocated before conventional memory
  403.      is. For example, if there is no more extended memory free
  404.      then conventional memory will be allocated. In either case
  405.      DOS32 sets up the 386 page tables such that the allocated 
  406.      memory is addressed in a straight linear block when it may
  407.      actually be physically scattered throughout RAM.
  408. ---8<----- API.DOC ----------
  409.  
  410.    vscreen dd      ?
  411.  
  412.    mov     eax,0ee42h
  413.    mov     edx,640*480
  414.    int     31h
  415.    jc      not_enough_memory
  416.    mov     vscreen,edx
  417.  
  418.    mov     eax,4f02h
  419.    mov     ebx,101h        ;our video mode..
  420.    int     10h
  421.  
  422.    Done. :)
  423.  
  424. 4. Put something on the virtual screen.
  425. 5. Flip the virtual screen out to video memory.
  426.    This is not the best way to do it, but it's fairly simple to understand.
  427.  
  428. flip    proc
  429.     push    eax ebx ecx edx esi edi ebp
  430.     xor    dx,dx        ;bank counter
  431.     xor    ebx,ebx        ;used to clear the buffer
  432.     mov    ebp,640*480    ;bytes left to move-counter
  433.     mov    esi,vscreen
  434.     mov    edi,videomem
  435.  
  436. outer_loop:
  437.     call    setbank
  438.     cmp    ebp,65536
  439.     jae    mov64k
  440.     mov    ecx,ebp
  441.     sub    ebp,ecx        ;update counter
  442.     shr    ecx,2        ;divide by 4 to get number of dwords to move
  443.     jmp    loop_start
  444. mov64k:    sub    ebp,65536
  445.     mov    ecx,16384
  446. loop_start:
  447.     mov    eax,[esi]    ;read a dword from the buffer
  448.     mov    [edi],eax    ;and write it to video mem
  449.     mov    [esi],ebx    ;clear the dword in the buffer
  450.     add    esi,4        ;update pointers
  451.     add    edi,4        ;update pointers
  452.     dec    ecx
  453.     jnz    loop_start    ;loop for 16384 times, this will move 65536 bytes..
  454.     inc    edx        ;increase bank counter
  455.     sub    edi,65536
  456.     cmp    ebp,3        ;check if we have more than 3 bytes left, 
  457.     ja    outer_loop    ;if so then jump up
  458.     or    ebp,ebp        ;are we completely done?
  459.     jz    flpbye        ;yes, then quit..
  460.  
  461.     mov    ecx,ebp        ;otherwise, move these bytes to video mem
  462. loop2_start:    ;this loop is used to move the bytes left
  463.     mov    al,[esi]    ;read one byte from buffer
  464.     mov    [edi],al    ;and write to video mem
  465.     mov    [esi],bl    ;clear buffer
  466.     inc    esi        ;increase source pointer
  467.     inc    edi        ;increase destination pointer
  468.     dec    ecx 
  469.     jnz    loop2_start    ;play it again, Sam!
  470. flpbye:    pop    ebp edi esi edx ecx ebx eax
  471.     retn
  472. flip    endp        
  473.  
  474. setbank proc
  475.     push    ax bx dx
  476.     mov     ax,4f05h
  477.     xor     bx,bx
  478.     int     10h
  479.     pop     dx bx ax
  480.     retn
  481. setbank endp
  482.  
  483.    OK! That's all folks.  Check out DOS32VBE.ASM included in the
  484.    package, I've put together the different sources listed in this
  485.    document, and made a simple filling-routine.  Enjoy, and feel free
  486.    to send comments to stuge@kuai.se! :)
  487.                                         -- Peter Stuge aka CareBear\ of ComeDY
  488.